# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     interface.py
    Description:   测试接口视图
 -------------------------------------------------
 """
from rest_framework import status
from rest_framework.response import Response

# from apps.api_tests.serializers import InterFaceCaseListSerializer
# Create your views here.

from utils.serializers import CustomModelSerializer
from apps.api_tests import models
from utils.viewset import CustomModelViewSet


class InterFaceSerializer(CustomModelSerializer):
    """
    接口-序列化器
    """

    class Meta:
        model = models.InterFace
        fields = '__all__'


class InterFaceListSerializer(CustomModelSerializer):
    """
    接口-列表 序列化器
    """
    from apps.api_tests.views.interface_cases import InterFaceCaseListSerializer

    cases = InterFaceCaseListSerializer(many=True, read_only=True, source="interfacecase_set")

    class Meta:
        model = models.InterFace
        fields = '__all__'


class TestInterFaceViewSet(CustomModelViewSet):
    """
    项目管理接口-视图
    """
    queryset = models.InterFace.objects.all()

    # 设置序列化器
    serializer_class = InterFaceSerializer
    list_serializer_class = InterFaceListSerializer

    # 设置查询过滤字段
    filterset_fields = ['project']

    denied_methods = ['retrieve']

    # def retrieve(self, request, *args, **kwargs):
    #     # 可以选择抛出 404 或者什么都不做
    #     return Response({'detail': 'Not found'}, status=status.HTTP_404_NOT_FOUND)
